package com.tanhua.server.controller;

import com.tanhua.domain.db.PageResult;
import com.tanhua.domain.vo.CommentVo;
import com.tanhua.server.service.LinkedCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class LinkedCommentController {
    @Autowired
    private LinkedCommentService linkedCommentService;

    /**
     * 评论列表
     */
    @GetMapping
    public ResponseEntity linkedCommentData(String movementId,
                               @RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize) {
        //1.调用service层 传入分页条件和发布
        PageResult<CommentVo> pageResult= linkedCommentService.getLinkedComment(0,movementId,page,pagesize);
        //2.返回状态信息
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 提交自己的评论
     */
    @PostMapping
    public ResponseEntity submitComments(@RequestBody Map map) {
        //1.调用service层 传入发布id和评论信息
        String publishId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        linkedCommentService.submitComments(publishId,comment);
        //2.返回状态信息
        return ResponseEntity.ok(null);
    }

    /**
     *  评论-点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity linkedLikeStatus(@PathVariable("id")String publishId) {
        //1.调用service层 传入分页条件和发布
        long linkedLikeCount=linkedCommentService.getLinkedLikeCount(publishId);
        //2.返回状态信息
        return ResponseEntity.ok(linkedLikeCount);
    }

    /**
     *  评论-取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity disLinkedLikeStatus(@PathVariable("id")String commentId) {
        //1.调用service层 传入分页条件和发布
        long disLinkedLikeCount=linkedCommentService.disLinkedLikeStatus(commentId);
        //2.返回状态信息
        return ResponseEntity.ok(disLinkedLikeCount);
    }



}
